﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Base;

public partial class Admin_Know_AnswerList : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind();
        }
    }
    private void Bind()
    {
        string strURl = Request.RawUrl;
        strURl = strURl.Substring(0, strURl.IndexOf(".aspx")) + ".aspx";
        PageNo1.Strurl = strURl;
        PageNo1.Table = "W_KnowAnswer left join W_KnowProblems on W_KnowAnswer.ProblemsID=W_KnowProblems.ID";
        PageNo1.FldName = "W_KnowAnswer.AddDate";
        PageNo1.StrGetFields = "W_KnowAnswer.ID,W_KnowAnswer.UserName,W_KnowAnswer.State,W_KnowAnswer.Detail,W_KnowAnswer.IP,W_KnowAnswer.AddDate,W_KnowAnswer.ProblemsID,W_KnowProblems.Caption";
        PageNo1.PageSize = 12;
        string strWhere = "1=1";
        if (Request.QueryString["page"] != "" && Request.QueryString["page"] != null)
        {
            PageNo1.Pageindex = Convert.ToInt32(Request.QueryString["page"].ToString());
            if (Session["strWhere"] != null)
                strWhere = Session["strWhere"].ToString();
            PageNo1.Where = strWhere;
            DataTable dt = PageNo1.BindViewDesc();
            if (dt.DefaultView.Count == 0)
            {
                lblMessage.Visible = true;
                lblMessage.Text = "暂无数据信息";
            }
            else
                lblMessage.Visible = false;
            grdAnswer.DataSource = dt.DefaultView;
            grdAnswer.DataBind();
        }
        else
        {
            if (GetRequest.GetQueryStringValue("V") != "")
            {
                switch (GetRequest.GetQueryStringValue("v"))
                {
                    case "1":
                        strWhere += " and W_KnowProblems.State=1";
                        break;
                    case "0":
                        strWhere += " and W_KnowProblems.State=0";
                        break;
                    default:
                        break;
                }
            }
            PageNo1.Where = strWhere;
            PageNo1.Pageindex = 1;
            Session["strWhere"] = strWhere;
            DataTable dt = PageNo1.BindViewDesc();
            if (dt.DefaultView.Count == 0)
            {
                lblMessage.Visible = true;
                lblMessage.Text = "暂无数据信息";
            }
            else
                lblMessage.Visible = false;
            grdAnswer.DataSource = dt.DefaultView;
            grdAnswer.DataBind();
        }
    }
    public string GetShortDate(string strDate)
    {
        if (strDate != string.Empty)
            return Convert.ToDateTime(strDate).ToShortDateString();
        else
            return string.Empty;
    }
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        for (int i = 0; i <= grdAnswer.Rows.Count - 1; i++)
        {
            CheckBox cbox = (CheckBox)grdAnswer.Rows[i].FindControl("CheckBox1");
            if (cbox.Checked == true)
            {
                int id = Convert.ToInt32(grdAnswer.DataKeys[i].Value);
                KnowAnswer ans = new KnowAnswer();
                int m = ans.Delete(id);
            }
        }
        Bind();
    }
    protected void grdAnswer_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int id = Convert.ToInt32(grdAnswer.DataKeys[e.RowIndex].Value.ToString());
        KnowAnswer ans = new KnowAnswer();
        int m = ans.Delete(id);
        Bind();
    }
}
